// pages/knowledge/knowimdex.js
function t(t, a, e) {
  return a in t ? Object.defineProperty(t, a, {
    value: e,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : t[a] = e, t;
}

var a,t = getApp(), e = t.requirejs("core"), a = t.requirejs("jquery"), s = t.requirejs("biz/diyform"), i = t.requirejs("biz/goodspicker");

t.requirejs("foxui");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    loaded: !1,
    loading: !0,
    allcategory: [],
    list: [],
    params: {},
    count: 0,
    defaults: {
      keywords: "",
      isrecommand: "",
      ishot: "",
      isnew: "",
      isdiscount: "",
      issendfree: "",
      istime: "",
      cate: "",
      order: "",
      by: "desc",
      merchid: 0
    },
    fromsearch: !1,
    searchRecords: [],
    areas: [],
    limits: !0,
    modelShow: !1,

  },
  newsdata(e){
    console.log(e)
    var url = e.currentTarget.dataset.url;
    clearInterval(this.data.durationIntval1);
    wx.setStorageSync('audioSeek', this.data.audioSeek);
    this.setData({
      audioSeek: '',
    })
    wx.navigateTo({
      url: url,
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  showlist(e){
    var url = e.currentTarget.dataset.url;
    clearInterval(this.data.durationIntval1);
    wx.setStorageSync('audioSeek', this.data.audioSeek);
    this.setData({
      audioSeek: '',
    })
    wx.navigateTo({
      url: url,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  imagesHeight: function (t) {
    console.log(t,4545)
    var a = t.detail.width, e = t.detail.height, i = t.target.dataset.type, s = this;
    wx.getSystemInfo({
      success: function (t) {
        var result = t.windowWidth / a * e;
        s.setData({
          result: result
        })
        var k = t.windowWidth / 1.7;
        s.setData({
          swiperheight: k
        });
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '加载中...',
    })
    var s = this;
    this.initCategory(), e.fromsearch ||this.getimgs(),this.getList(),this.getNews();
    e.get("goods/get_shop", {}, function (e) {
      console.log(e, 31313123);
      wx.setNavigationBarTitle({
        title: e.shopdata.name
      })
      s.setData({
       shopdata:e.shopdata
      });
      wx.hideLoading();
    });
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  onShareAppMessage: function () {
    var t = null, a = null;
   var s= this;
   var name= s.data.shopdata.name;
   console.log(name,353543);
    return this.data.diytitle && (t = "/pages/knowledge/knowimdex", a = name),
      s.onShareAppMessage(t, a);
  },
  musicurl(e){
    clearInterval(this.data.durationIntval1);
    wx.setStorageSync('audioSeek', this.data.audioSeek);
    this.setData({
      audioSeek:'',
    })

    var id = wx.getStorageSync('id');
    var type = wx.getStorageSync('type')
    wx.navigateTo({
      url: '/pages/knowledge/videoknow/index?id='+id +'&type='+type,
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var t = this;
    var isPlayAudio = wx.getStorageSync('isPlayAudio');
    var audioSeek = wx.getStorageSync('audioSeek');
    var id = wx.getStorageSync('id');
    console.log(isPlayAudio,7878)
    if (isPlayAudio==true){
      this.data.durationIntval1 = setInterval(function () {
        if (t.data.audioSeek == null || t.data.audioSeek==''){
          var seek = audioSeek;
        }else{
          var seek = t.data.audioSeek;
        }
        t.setData({
          audioSeek: seek + 1
        })
        // wx.setStorageSync('audioSeek', seek + 1)
      }, 1000)

    }else{
      clearInterval(this.data.durationIntval1);
    }

    this.data.fromsearch && this.setFocus();
    wx.getSetting({
      success: function (e) {
        var a = e.authSetting["scope.userInfo"];
        t.setData({
          limits: a,
          isPlayAudio: isPlayAudio
        });
      }
    });
  },
   getNews:function()
   {
     var t = this;
     e.get("goods/get_newsknow", {}, function (e) {
       t.setData({
         newsdata: e.newsdata,
       });
       wx.hideLoading();
     });
   },
  initCategory: function () {
    var t = this;
    e.get("goods/get_categoryknow", {}, function (e) { 
      t.setData({
        allcategory: e.allcategory,
        category_parent: e.allcategory.parent,
        category_child: [],
        category_third: [],
        catlevel: e.catlevel,
        opencategory: e.opencategory,
        show: !0
      });
    });
  },
  getimgs: function () {
    var t = this;
    e.get("goods/get_imgs", {}, function (e) {
       console.log(e);
      t.setData({
        allimgs: e.allimgs,
      
      });
    });
  },

  getList: function () {
    var t = this;
    t.setData({
      loading: !0
    }), t.data.params.page = t.data.page, e.get("goods/get_listknow", t.data.params, function (e) {
      var a = {
        loading: !1,
        count: e.total,
        show: !0
      };
    t.setData({list:e.list})
    });
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.data.loaded || this.data.list.length == this.data.total || this.getList();
  },
  // 下拉刷新
  onPullDownRefresh: function () {
    var s = this;
    this.initCategory(), e.fromsearch || this.getimgs(), this.getList(), this.getNews();
    wx.stopPullDownRefresh();
  },
  onUnload: function () {
    console.log(4545)
    //卸载页面，清除计步器
    
  },

})